package com.bosssoft.hr.train.j2se.colletion;

import com.bosssoft.hr.train.j2se.pojo.User;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @Classname: HashMapDemo
 * @Description:使用HashMap存储 10个 User，Map的key为用户id，Value为对象，并且迭代输出
 * @author: zoubinyan
 * @Date: 2023/2/22
 */
@Slf4j
public class HashMapDemo {

    public static void main(String[] args) {
        out();
    }
    public static void out(){
        HashMap<Long, User> users = new HashMap<>(0);
        int c=10;
        for (int i = 0; i < c; i++) {
            User user = new User();
            user.setId((long) i);
            users.put((long) i, user);
        }
        //遍历显示
        Iterator<Map.Entry<Long, User>> iterator = users.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Long, User> entry = iterator.next();
            log.info("log:" + "{}", entry.getKey().toString() + "####" + entry.getValue());
        }
    }
}


